home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_546 / 2view / source / arexx.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  217 lines

  1.  
  2. /*ARexx.c:  This is the ARexx support code module*/
  3.  
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <clib/intuition_protos.h>
  8. #include "minrexx.h"
  9. #include "arexx.h"
  10.  
  11. #include <pragmas/exec_pragmas.h>
  12. #include <pragmas/intuition_pragmas.h>
  13.  
  14. enum ButtonTypes {none=0,select,menu};
  15. typedef enum ButtonTypes ButtonTypes;
  16.  
  17. extern struct Library *SysBase;
  18. extern struct Library *IntuitionBase;
  19.  
  20. struct RexxMsg *rexxMsg;
  21.  
  22. /*These variables are defined in 2View.c, and are used to enable the ARexx*/
  23. /*routines to communicate with the rest of the program*/
  24.  
  25. /*This variable is used to tell 2View to quit or advance*/
  26. extern ButtonTypes rexxAbort;
  27.  
  28. extern struct Screen *prevScreen;   /*The current screen*/
  29.  
  30. extern char *picFilename;  /*The filename of the current picture*/
  31. extern char *playListFilename;     /*The name of the playlist*/
  32.  
  33. extern UWORD ticks;  /*The number of ticks remaining to show each picture*/
  34. extern UWORD ticksRemaining;   /*The time left to show the current picture*/
  35.  
  36. extern BOOL loop;       /*TRUE if the user specified 'loop'*/
  37. extern BOOL printPics;       /*TRUE if we're printing each picture*/
  38.  
  39. extern char *version;       /*2View's version string*/
  40.  
  41. void rQuit(char *p);
  42. void rAdvance(char *p);
  43. void rGet(char *p);
  44. void rPicToFront(char *p);
  45. void rPicToBack(char *p);
  46. void rPrint(char *p);
  47.  
  48. struct rexxCommandList commandList[] =
  49. {
  50.    { "quit" , (APTR)&rQuit },     /*Abort a picture sequence*/
  51.    { "advance", (APTR)&rAdvance },  /*Show the next picture in the sequence*/
  52.    { "get", (APTR)&rGet },          /*Multi-purpose*/
  53.    { "pictofront", (APTR)&rPicToFront }, /*Bring the picture to the front*/
  54.    { "pictoback", (APTR)&rPicToBack },   /*Send the picture to the back*/
  55.    { "print", (APTR)&rPrint },           /*Print the picture*/
  56.    { NULL, NULL }
  57. };
  58.  
  59. char portName[16];
  60. char arexxBuf[140];
  61.  
  62.  
  63. /*Open the ARexx port*/
  64. long initRexxPort(void)
  65. {
  66.    determinePortName(portName);  /*Get the port name*/
  67.  
  68.    /*Ask minrexx to open the port and return the port's signal bit*/
  69.    return(upRexxPort(portName,commandList,"rx",(APTR)&disp));
  70. }
  71.  
  72. char *result="RESULT";
  73. UBYTE errorNum=0;
  74.  
  75. /*Determine what the ARexx port name should be.  The first running instance*/
  76. /*of 2View should have an ARexx port named '2View.1'.  The second, '2View.2'*/
  77. /*etc.    This starts at '2View.1' and works up until it finds a free space*/
  78. /*(up to 2View.99)*/
  79. void determinePortName(char *portName)
  80. {
  81.    ULONG c=1;
  82.    UBYTE len;
  83.  
  84.    strcpy(portName,"2View.");
  85.  
  86.    do
  87.    {
  88.       len=stcu_d(&portName[6],c++);
  89.       portName[6+len]=NULL;
  90.    }
  91.    while(FindPort(portName)!=NULL && c<100);
  92.    if(FindPort(portName)!=NULL)
  93.       exit(50);
  94.    return;
  95. }
  96.  
  97. /*The ARexx command dispatch function.    This calls the functions associated*/
  98. /*with a particular command*/
  99. int disp(struct RexxMsg *msg,struct rexxCommandList *dat,char *p)
  100. {
  101.    rexxMsg=msg;
  102.  
  103.    /*Call the function that supports the command*/
  104.    ((int (*)())(dat->userdata))(p);
  105.  
  106.    /*Reply to ARexx, using the reply string and error number set by the*/
  107.    /*function just called*/
  108.    replyRexxCmd(rexxMsg,errorNum,0,arexxBuf);
  109.    errorNum=0;
  110.    return(1);  /*1 means that minrexx shouldn't reply to the rexx message*/
  111. }
  112.  
  113. /*quit:  Abort a sequence of pictures*/
  114. void rQuit(char *p)
  115. {
  116.    rexxAbort=menu;    /*It's like the user pressed the right mouse button*/
  117.    strcpy(arexxBuf,result);
  118. }
  119.  
  120. /*advance:  Advance to the next picture in this sequence*/
  121. void rAdvance(char *p)
  122. {
  123.    rexxAbort=select;    /*Like pressing the left mouse button*/
  124.    strcpy(arexxBuf,result);
  125. }
  126.  
  127. /*get:    This function gets information about the current picture/playlist*/
  128. void rGet(char *p)
  129. {
  130.    p++;
  131.  
  132.    /*The picture's filename*/
  133.    if(stricmp(p,"name")==0)
  134.       strcpy(arexxBuf,picFilename);
  135.  
  136.    /*The picture width*/
  137.    else if(stricmp(p,"width")==0)
  138.       stcu_d(arexxBuf,prevScreen->Width);
  139.  
  140.    /*The height*/
  141.    else if(stricmp(p,"height")==0)
  142.       stcu_d(arexxBuf,prevScreen->Height);
  143.  
  144.    /*The number of bitplanes*/
  145.    else if(stricmp(p,"depth")==0)
  146.       stcu_d(arexxBuf,prevScreen->BitMap.Depth);
  147.  
  148.    /*The viewmodes of the picture (HAM, HIRES, LACE, etc.*/
  149.    else if(stricmp(p,"viewmodes")==0)
  150.       stci_h(arexxBuf,prevScreen->ViewPort.Modes);
  151.  
  152.    /*The time left to display this picture*/
  153.    else if(stricmp(p,"timeleft")==0)
  154.       stcu_d(arexxBuf,ticksRemaining);
  155.  
  156.    /*The time to display each picture*/
  157.    else if(stricmp(p,"timeperpicture")==0)
  158.       stcu_d(arexxBuf,ticks);
  159.  
  160.    /*The version number and date of this program*/
  161.    else if(stricmp(p,"version")==0)
  162.       strcpy(arexxBuf,&version[12]);
  163.  
  164.    /*The name of the playlist, or '?NONE?' if there is no playlist*/
  165.    else if(stricmp(p,"playlistname")==0)
  166.       if(playListFilename==NULL)
  167.      strcpy(arexxBuf,"?NONE?");
  168.       else
  169.      strcpy(arexxBuf,playListFilename);
  170.  
  171.    /*Returns 'TRUE' if the user specified 'loop' on the command line, 'FALSE'*/
  172.    /*if he didn't*/
  173.    else if(stricmp(p,"looping")==0)
  174.       if(loop)
  175.      strcpy(arexxBuf,"TRUE");
  176.       else
  177.      strcpy(arexxBuf,"FALSE");
  178.  
  179.    /*Returns 'TRUE' if the user specified 'print' on the command line,*/
  180.    /*FALSE if she didn't*/
  181.    else if(stricmp(p,"printpictures")==0)
  182.       if(printPics)
  183.      strcpy(arexxBuf,"TRUE");
  184.       else
  185.      strcpy(arexxBuf,"FALSE");
  186.  
  187.    /*Otherwise, we don't understand, so return an error*/
  188.    else
  189.    {
  190.       errorNum=100;
  191.       strcpy(arexxBuf,"ERROR");
  192.    }
  193. }
  194.  
  195. /*pictofront:  Send the picture's screen to the front*/
  196. void rPicToFront(char *p)
  197. {
  198.    ScreenToFront(prevScreen);
  199.    strcpy(arexxBuf,result);
  200. }
  201.  
  202. /*pictoback:  Send the picture's screen to the back*/
  203. void rPicToBack(char *p)
  204. {
  205.    ScreenToBack(prevScreen);
  206.    strcpy(arexxBuf,result);
  207. }
  208.  
  209. /*print:  Print the currently displayed picture*/
  210. void rPrint(char *p)
  211. {
  212.    dumpRastPort(&(prevScreen->RastPort),&(prevScreen->ViewPort));
  213.    strcpy(arexxBuf,result);
  214. }
  215.  
  216. /*End of ARexx.c*/
  217.